<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="实装批号" prop="batchNoBase">
        <el-input
          v-model="queryParams.batchNoBase"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="起始时间" prop="startTime">
        <el-date-picker
          v-model="queryParams.startTime"
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期时间"
          :value-format="'yyyy-MM-dd HH:mm:ss'"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="截止时间" prop="endTime">
        <el-date-picker
          v-model="queryParams.endTime"
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期时间"
          :value-format="'yyyy-MM-dd HH:mm:ss'"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="匹配通道类型" prop="sourceIdMatch">
        <el-select
          v-model="queryParams.sourceIdMatch"
          placeholder="请选择通道类型"
        >
          <el-option
            v-for="item in channels"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="匹配批号" prop="batchNoMatch">
        <el-input
          v-model="queryParams.batchNoMatch"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="dataList">
      <el-table-column
        prop="batchNoBase"
        label="实装批号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="startTimeBase"
        label="实装起批时间"
        align="center"
      ></el-table-column>
      <el-table-column label="匹配来源" align="center" prop="sourceIdMatch">
        <template slot-scope="scope">
          <span>{{ getSourceIdMatchName(scope.row.sourceIdMatch) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="匹配批号"
        align="center"
        prop="batchNoMatch"
      ></el-table-column>
      <el-table-column
        label="匹配起批时间"
        align="center"
        prop="startTimeMatch"
      ></el-table-column>
      <el-table-column
        label="起批间隔(s)"
        align="center"
        prop="timeInterval"
      ></el-table-column>
      <el-table-column
        label="匹配点数"
        align="center"
        prop="matchSize"
      ></el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getDict,
  getAirPlaneList,
  getAirPlaneDelete,
  getBatchMatchList,
} from "@/api/service";
import moment from "moment";

export default {
  name: "Datasource",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      channels: [],
      // 表格树数据
      dataList: [],
      // 重新渲染表格状态
      refreshTable: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNoBase: undefined,
        startTime: moment().subtract(1, "days").format("YYYY-MM-DD HH:mm:ss"),
        endTime: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"),
        sourceIdMatch: undefined,
        batchNoMatch: undefined,
      },
      mulData: [
        {
          label: "6203（智能1）",
          value: 6203,
        },
        {
          label: "8203（实装）",
          value: 8203,
        },
        {
          label: "6233（智能2）",
          value: 6233,
        },
      ],
    };
  },
  mounted() {
    getDict("channel_type").then((res) => {
      console.log("channel_type", res.data);
      if (res.code === 200) {
        const data = res.data.map((item) => {
          return {
            value: item.dictValue,
            label: item.dictLabel,
          };
        });
        this.channels = data;
      }
    });
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      getBatchMatchList(this.queryParams).then((response) => {
        this.dataList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    getSourceIdMatchName(id) {
      let name = "";
      this.mulData.forEach((item) => {
        name = item.value == id ? item.label : '';
      });
      return name;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //关闭库相关
    closeDialog() {
      this.dialogVisible = false;
      this.dialogOpen = false;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
